//
//  main.cpp
//  Practice7
//
//  Created by 赵世杰 on 2020/6/26.
//  Copyright © 2020 zhaoshijie. All rights reserved.
//

#include <iostream>
#include <array>

using namespace std;

const int Max = 5;
const int SLEN = 30;

const int Seasons = 4;
const char *seasons[Seasons] = {"spring", "summer", "fall", "winter"};

struct box
{
    char maker[40];
    float height;
    float width;
    float length;
    float volume;
};

struct Student
{
    char fullName[SLEN];
    char hobby[SLEN];
    int ooplevel;
    
};

double computeAvg(int num0,int num1);

array<float, 10> inputAchievement();
void printAchievement(array<float, 10> array);
double computeAvgAchievement(array<float, 10> array);


void transmitVaule(char marker[] ,int count ,float height,float width,float length,float volume);
void transmitVaule2(box box);

double probability(unsigned numbers,unsigned picks,unsigned numbers2);

long compultFactorial(long number);

int Fill_array(double array[],int index);
void Show_array(double array[],int index);
void Reverse_array(double array[],int index);

//int fill_array(double ar[] , int limit);
double * fill_array(double ar[] , int limit);
void show_array(const double ar[], const double ar1[]);
void revalue(double r , double ar[], const double ar1[]);

void fill(double pa[]);
void show(double da[]);
void fill(array<double, Seasons> pa);

int getinfo(Student pa[],int n);
void display1(Student stu);
void display2(const Student *ps);
void display3(const Student pa[], int n);


double add(double x,double y);
double calculate(double x , double y, double (*pf)(double ,double));



int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    
    
    /*
     
     1、
    int num0;
    
    int num1;
    
    cout << "输入两个数" << endl;
    
    cout << "第一个数" << endl;
    cin >> num0;
    
    cout << "第二个数" << endl;
    cin >> num1;
    
    
    while (num0 != 0 && num1 != 0) {
        
        //  计算
        double result = computeAvg(num0, num1);
        
        cout << "调和平均叔为:" << result << endl;
        

        cout << "第一个数" << endl;
        cin >> num0;
        
        cout << "第二个数" << endl;
        cin >> num1;
        
    }
     */
    
    /*
    
//    2、
    
    
    array<float, 10> result = inputAchievement();
    printAchievement(result);
    double avg = computeAvgAchievement(result);
    cout << "平均值为：" << avg << endl;
     */
    
    /*
    // 3、
    box box ;
    
    char ch;
    
    cin.get(ch);
    
    int count = 0;
    
    while (ch != '\n') {
        
        if(count>=sizeof(box.maker)/sizeof(box.maker[0]))
        {
            break;
        }
        
        box.maker[count] = ch;
        
        cin.get(ch);
        
        count ++;
        
    }
    
    box.height = 165;
    box.width = 30;
    box.length = 100;
    box.volume = 26.98;
    
//    transmitVaule(box.maker, 40, box.height, box.width, box.length, box.volume);
    
    transmitVaule2(box);
     */
    
    /*
     
     // 4、
    double result = probability(47,5,27);
    cout << "中奖机率: " << result;
    */
    
    /*
     
     // 5、
    cout << "请输入一个数，计算阶乘:" << endl;
    
    int index ;
    
    cin >> index;
    
    cin.get();
    
    cin.clear();
    
    long factorial = compultFactorial(index);
    
    cout <<index << "的阶乘: " << factorial << endl;
    */
    
    
    /*
    // 6、
    
    double array[7] = {0.0} ;
    
    int count = Fill_array(array, 7);
    
    cout << "数字的个数" << count << endl;
    
    
    Show_array(array, 7);
    
    Reverse_array(array,7);
    
    Show_array(array, 7);
    */
    
    
    /*
    //  7.
    
    
    double properties[Max];
    
    double *size = fill_array(properties,Max);
    
    show_array(properties, size);
    
    if(properties != size)
    {
        cout << "Enter revaluation factor: ";
        
        double factor;
        
        while (!(cin >> factor))
        {
            cin.clear();
            
            while (cin.get() != '\n') {
                
                continue;
            }
            
            cout << "Bad input;Please enter a number: ";
            
        }
        
        revalue(factor, properties, size);
        
        show_array(properties, size);
        
    }
    
    cout << "Done.\n";
    
    cin.get();
    cin.get();
     */
    
    
//    double expenses[Seasons];
//    fill ( expenses );
//    show ( expenses );
    
    /*
    //  结论，不传地址修改不了内容。如果要修改数组中的内容必须修改传地址过去。
    array<double, Seasons> seasons ;
    fill(seasons);
     */
    
    
    /*
    cout << "Enter class size: ";
    
    int class_size;
    
    cin >> class_size;
    
    while (cin.get() != '\n')
    {
        continue;
    }
    
    Student *ptr_stu = new Student[class_size];
    
    int entered = getinfo(ptr_stu, class_size);
    
    for (int i=0; i<entered; i++)
    {
        Student stu = ptr_stu[i];
        
//        cout << stu.fullName << stu.hobby << stu.ooplevel << endl;
        display1(stu);
        display2(&stu);
        
    }
    
    display3(ptr_stu, entered);
    
    delete [] ptr_stu;
    
    cout << "Done\n";
    */
    
    
    int num0;
    int num1;
    
    double (*pf[100])(double ,double);

    int count = 0;
    
    while (cin >> num0 && cin >> num1 && count<100) {
        
        double value = calculate(num0, num1, add);
        
        cout << value << endl;
        
        count ++;
        
        pf[count] = add;
        
    }
    
    
    
    
    
    return 0;
}

double add(double x,double y)
{
    return x+y;
}

double calculate(double x , double y, double (*pf)(double ,double))
{
    double value = (*pf)(x,y);
    
    return value;
}

/*
void display1(Student stu)
{
    cout << "display1打印结果";
    
    cout << "fullName: " << stu.fullName << "  hobby: " << stu.hobby << "  ooplevel: " << stu.ooplevel << endl;
    
}

void display2(const Student *ps)
{
    cout << "display2打印结果";
    
    cout << "fullName: " << ps->fullName << "  hobby: " << ps->hobby << "  ooplevel: " << ps->ooplevel << endl;
    
}

void display3(const Student pa[], int n)
{
    cout << "display3打印结果" << endl;
    
    for (int i=0; i<n; i++)
    {
        Student stu = pa[i];
        
        cout << "fullName: " << stu.fullName << "  hobby: " << stu.hobby << "  ooplevel: " << stu.ooplevel << endl;
        
    }
    
    
}


int getinfo(Student pa[],int n)
{
    for (int i=0; i<n; i++) {
        
        Student student;
        
        cout << "请输入学生内容" << endl;
        
        cout << "fullname : " ;

        char fullName[30];
        
        cin.get(fullName, 30).get();
        
        stpcpy(student.fullName, fullName);
        
        cout << "请输入学生的爱好" << endl;
        
        cout << "fullname : " ;

        char hobby[30];
        
        cin.get(hobby, 30).get();
        
        stpcpy(student.hobby, hobby);
        
        cout << "请输入学生的等级" << endl;
        
        cout << "fullname : " ;

        int ooplevel;
        
        cin >> ooplevel;
        
        cin.get();
        cin.clear();
        
        student.ooplevel = ooplevel;
        
        pa[i] = student;
        
    }
    
    
    return n;
    
    
}
*/



/*
void fill(array<double, Seasons> pa)
{
    for (int i=0; i<Seasons; i++)
    {
        pa[i] = 0.01;
    }
}

void fill(double pa[])
{
    for (int i = 0; i<Seasons; i++) {
        
        cout << "Enter " << seasons[i] << " expenses: ";
        
        cin >> pa[i];
    }
}

void show(double da[])
{
    double total = 0;
    
//    double expendsList[Seasons];
    
    
    cout << "\nEXPENSES\n";
    
    for (int i=0; i<Seasons; i++)
    {
        cout << seasons[i] << ":$" << da[i] << endl;
        
        total += da[i];
    }
    cout << "Total Expenses:$" << total << endl;
    
}
 */


/*
double * fill_array(double ar[] , int limit)
{
    double temp ;
    int i;
    
    for (i = 0; i<limit; i++)
    {
        cout << "Enter valeu #" << (i+1) << ": ";
        
        cin >> temp;
        
        if(!cin)
        {
            cin.clear();
            
            while (cin.get() != '\n')
            {
                continue;
            }
            
            cout << "Bad input;inout process terminated.\n";
            break;
        }
        else if (temp < 0)
        {
            break;
        }
        
        ar[i] = temp;
        
    }
    
    return ar + i + 1;
}


void show_array(const double ar[], const double ar1[])
{
    int i = 0;
    
    const double *address;
    
    address = ar + 1;
    
    while (address != ar1) {
        
        cout << "Property # " << (i+1) << ": $";
        
        cout << ar[i] << endl;
        
        i++;
        
        address ++;
        
    }
    
    
}

void revalue(double r , double ar[], const double ar1[])
{
    
    int i = 0;
    
    const double *address;
    
    address = ar;
    
    while (address != ar1) {
        ar[i] *= r;
        
        i++;
        
        address ++;
        
    }
    
}
*/

/*
int Fill_array(double array[],int index)
{
    cout << "请输入内容" << endl;
    
    double number;
    
    int count = 0;
    
    while (cin >> number && count<index) {
        
        array[count] = number;
//        array[index] = 1;
        
        count++;
        
    }
    
    return count;
    
}


void Show_array(double array[],int index)
{
    cout << "输出数组内容：" << endl;
    
//    double arasda[20] = *array;
    
    for (int i=0; i<index; i++) {
        
        cout << i << "位置的值为：" << array[i] << endl;
        
    }
    
}

void Reverse_array(double array[],int index)
{
    for (int i = 1; i<index/2.0; i++) {
        
        double value = array[i];
        
        array[i] = array[index-i-1];
        
        array[index-i-1] = value;
        
    }
    
    
}
*/


/*
long compultFactorial(long number)
{
    if(number <= 0)
    {
        return 1;
    }
    
    
    long result = number * compultFactorial(number-1);
    
    return result;
    
}
 */



/*
double probability(unsigned numbers,unsigned picks,unsigned numbers2)
{
    
    double result = 1;
    
    
    for (int i=numbers , j = picks; i>0 && j>0 ; i--,j--) {
        
        result = result * numbers / picks;
    }
    
    result = result *numbers2;
    
    return result;
}
 */



/*
void transmitVaule(char marker[] ,int count ,float height,float width,float length,float volume)
{
    box box;
    strcpy(box.maker, marker);
    box.height = height;
    box.width = width;
    box.length = length;
    box.volume = volume;
    
    cout << "打印结构体数据" << endl;
    
    cout << "maker: ";
    
    
    for (int i=0; i<sizeof(box.maker)/sizeof(box.maker[0]); i++) {
        
        if(box.maker[i] == '\0')
        {
            break;
        }
        
        cout << box.maker[i];
        
    }
    cout << endl;
    
    cout << "height: " << box.height << endl;
    cout << "width: " << box.width << endl;
    cout << "length: " << box.length << endl;
    cout << "volume: " << box.volume << endl;
    
    

}

void transmitVaule2(box box)
{
    double volue = box.height*box.width*box.length;
    
    box.volume = volue;
    
    cout << "volume: " << box.volume << endl;
    
}
*/

/*
double computeAvg(int num0,int num1)
{
    double avg = 2.0*num0*num1/(num0+num1);
    
    return avg;
    
}
 */

/*
array<float, 10> inputAchievement()
{
    
    array<float, 10> achievementArray ;
    
    cout << "请输入成绩，q结束" << endl;
    
    for (int i=0; i<achievementArray.size(); i++) {
        
        float achievement;
        
        cin >> achievement;
        
        achievementArray[i] = achievement;
        
    }
    
    return achievementArray;
}


void printAchievement(array<float, 10> array)
{
    
    
    for (int i=0; i<array.size(); i++) {
        
        if(array[i] <=0)
        {
            break;
        }
        
        cout << "打印数据"<< i <<":" << array[i] << endl;
        
    }
    
    
}


double computeAvgAchievement(array<float, 10> array)
{
    float sum = 0;
    
    int count = 0;
    
    for (int i=0; i<array.size(); i++) {
        
        if(array[i] <=0)
        {
            break;
        }
        
        sum += array[i];
        
        count++;
        
    }
    
    if(count == 0)
    {
        return 0;
    }
    else
    {
        return sum/count;
    }
}
 */

